//
//  YTPickerOrderViewModel.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/8/2.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTPickerOrderViewModel.h"
#import "YTDriverCarModel.h"
#import "YTPriceBonusModel.h"

#import "YTDriverCarServices.h"
#import "YTUserProfileServices.h"
#import "YTOrderServices.h"

@interface YTPickerOrderViewModel ()
@property (strong, nonatomic, readwrite) RACCommand *loadCarList;
@property (strong, nonatomic, readwrite) RACCommand *loadBonusList;
@end

@implementation YTPickerOrderViewModel

- (void)initialize {
    _carArray = [NSArray array];
    _bonusArray = [NSArray array];
    [self loadData];
}

- (void)loadData {
    @weakify(self);
    _loadCarList = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(RACTuple *data) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        dict[@"page"] = @"1";
        dict[@"maxPassenger"] = data.first;
        dict[@"maxLuggage"] = data.second;
        dict[@"applyStatus"] = @"1";
        dict[@"status"] = @"1";
        return [[YTDriverCarServices getCarListData:dict] doNext:^(NSDictionary *response) {
            @strongify(self);
            NSDictionary *responseData = response[@"responseData"];
            self.carArray = [NSArray yy_modelArrayWithClass:[YTDriverCarModel class] json:responseData[@"carList"]];
        }];
    }];
    
    _loadBonusList = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [[YTUserProfileServices bonusList:@{@"Status" : @"1"}] doNext:^(NSDictionary *response) {
            @strongify(self);
            NSDictionary *responseData = response[@"responseData"];
            self.bonusArray = [NSArray yy_modelArrayWithClass:[YTPriceBonusModel class] json:responseData[@"couponKeyList"]];
        }];
    }];
}

@end
